﻿using System.Collections.Generic;
using System.Linq;
using Sustainalytics.CRT.Synchronization;
using Sustainalytics.ESGRatings.BusinessLogic;
using Sustainalytics.Governance.Synchronization;
using Sustainalytics.ReportGenerator.BL;
using Sustainalytics.Synchronization.Interface;
using Sustainalytics.Synchronization.Validation.ValidationRules.Common;

namespace Sustainalytics.Synchronizations.ValidationSyncStep
{
    public class SyncStepsDictionary
    {
        private readonly Dictionary<BusinessResearchProduct, List<ISyncStep>> associatedSyncSteps = new Dictionary<BusinessResearchProduct, List<ISyncStep>>
        {
            {
                BusinessResearchProduct.Comprehensive, new List<ISyncStep>
                {
                    new ESGRatingsPreparationSyncStep(),
                    new ReportDataPreparationSyncStep()
                }
            },
            {
                BusinessResearchProduct.CorporateGovernance, new List<ISyncStep>
                {
                    new GovernanceComputationSyncStep()
                }
            }
        };

        public SyncStepsDictionary(SyncContext context)
        {
            associatedSyncSteps[BusinessResearchProduct.Comprehensive].Add(GetFocusedRatingsSyncStep(context));
            associatedSyncSteps.Add(BusinessResearchProduct.Core, new List<ISyncStep> { GetFocusedRatingsSyncStep(context) });
        }


        private ISyncStep GetFocusedRatingsSyncStep(SyncContext context)
        {
            var syncStepDescription = context.SelectedSteps.FirstOrDefault(x => x == SyncStepOrder.FocusedRatingsComputationOutput2);
            if (syncStepDescription != default(SyncStepOrder))
            {
                return new FocusedRatingsComputationSyncStep2();
            }

            return new FocusedRatingsComputationSyncStep2();
        }

        public List<ISyncStep> GetSteps(BusinessResearchProduct researchProduct)
        {
            return associatedSyncSteps[researchProduct];
        }
    }
}